package jp.sourceforge.akjrcp.text_douga.video;

import java.util.ArrayList;
import java.util.List;



import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class JpegKeeper {
	public static Log log = LogFactory.getLog(JpegKeeper.class);
	int maxKeep=30;
	private List<byte[]> byteList=new ArrayList<byte[]>();
	private boolean finished=false;
	
	public byte[] nextImage(){
		while(finished==false && byteList.size()==0){
			try {
				//log.info("no image:");
				Thread.sleep(30);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		if(byteList.size()>0){
			byte[] bts=byteList.remove(0);
			
			return bts;
		}
		
		
		//log.trace(debug);
			return null;
		
	}
	int debug=0;
	
	public void addImage(byte[] bytes){
		while(byteList.size()>=maxKeep){
			try {
				//log.info("over:"+byteList.size());
				Thread.sleep(20);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		debug++;
		byteList.add(bytes);
		//log.info("added:"+byteList.size());
	}

	public boolean isFinished() {
		return finished;
	}

	public void setFinished(boolean finished) {
		this.finished = finished;
	}


}
